﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBUtils;


public partial class EmployeeInfo_defaultInfo : System.Web.UI.Page
{
    int empID;//存放当前用户ID
    DBUtils.Employee empInfo=new Employee();

    protected void Page_Load(object sender, EventArgs e)
    {
        empID = Convert.ToInt32(Session["EmployeeID"]);//取出当前用户ID号码

        if (Request.QueryString["id"] ==null)//如果此时不是查看其他用户的信息
        {
            if (!IsPostBack)//如果此时为刷新页面
            {
                search(empID);//显示员工信息
            }
        }
        else//若此时是在查看其他用户信息
        {
            empID = Convert.ToInt32(Request.QueryString["id"]);//取出所要查看的用户ID号码
            search(empID);//显示员工信息
            btnSubmit.Enabled = false;//不能修改其他用户的信息
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int isSuccess;//存储修改是否成功
        isSuccess = EmployeeInfo.UpdateSelfIntro(Convert.ToInt32(lblEmpID.Text), tbSelfintro.Text.Trim());//进行修改
        if (isSuccess == 0)//判断修改结果
        {
            lblMessage.Text = "修改失败";
        }
    }


    /// <summary>
    /// 显示员工的具体信息
    /// </summary>
    /// <param name="empID">员工编号</param>
    private void search(int empID)
    {
        DBUtils.Employee.GetEmployeeInfo(empID, empInfo);

        this.lblEmpID.Text = empInfo.EmployeeID.ToString();
        this.lblEmail.Text = empInfo.Email.ToString();
        this.lblName.Text = empInfo.Name.ToString();
        this.lblManage.Text = empInfo.ManagerName.ToString();
        this.lblDept.Text = empInfo.DeptName.ToString();
        this.lblExt.Text = empInfo.Telephone.ToString();

        this.tbSelfintro.Text = empInfo.SelfIntro.ToString().Trim();


        if (EmployeeInfo.GetUserPhotos(empID) != null)//如果用户有照片
        {
            Literal1.Text = "<img src='Photo.aspx?id=" + empID + "'>";//显示照片
        }


    }

    /// <summary>
    /// 单击经理名，则弹出客户端邮件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lblManage_Click(object sender, EventArgs e)
    {
        DBUtils.Employee.GetEmployeeInfo(empID, empInfo);
        Response.Redirect("mailto:"+empInfo.ManagerEmail);
    }
    protected void lblEmail_Click(object sender, EventArgs e)
    {
        Response.Redirect("mailto:" + lblEmail.Text);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("asdfasdfsadf");
    }
}
